import msgpack from 'msgpack-lite';
class packer {
    static pack(head: number, t: any) {
        // 假设可能存在t为null或undefined的情况，添加检查
        if (t === null || t === undefined) {
            throw new Error('Cannot pack null or undefined value');
        }
        let obj = { a: head, d: t };
        return msgpack.encode(obj);
    }

    static unpack(buffer: Buffer | Uint8Array | number[]) {
        // 假设可能存在buffer为null或undefined的情况，添加检查
        if (buffer === null || buffer === undefined) {
            throw new Error('Cannot unpack null or undefined buffer');
        }
        let obj = msgpack.decode(buffer);
        return { head: obj.a, data: obj.d };
    }
}